<?php

namespace app\admin\model\jdy;

use think\Model;

class Anchang extends Model
{
    // 表名
    protected $name = 'jdy_anchang';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'fee_type_text',
        'type_text'
    ];
    

    
    public function getFeeTypeList()
    {
        return ['Month' => __('Month'),'Season' => __('Season'),'HalfYear' => __('Halfyear'),'Year' => __('Year')];
    }     

    public function getTypeList()
    {
        return ['住宅' => __('住宅'),'商辦' => __('商辦'),'工廠' => __('工廠'),'其他' => __('其他'),'廠商' => __('廠商')];
    }     


    public function getFeeTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['fee_type']) ? $data['fee_type'] : '');
        $list = $this->getFeeTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function building()
    {
        return $this->belongsTo('Building', 'building_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function room()
    {
        return $this->belongsTo('Room', 'room_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
